package org.pisces.cas;

import org.apereo.cas.config.CasWebflowContextConfiguration;
import org.apereo.cas.web.flow.CasWebflowConfigurer;
import org.pisces.cas.action.MyValidateAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;
import org.springframework.webflow.execution.Action;

@Configuration("somethingConfiguration")
@AutoConfigureBefore(value = CasWebflowContextConfiguration.class)
public class SomethingConfiguration {

    @Autowired
    @Qualifier("loginFlowRegistry")
    private FlowDefinitionRegistry loginFlowDefinitionRegistry;

    @Autowired
    private FlowBuilderServices flowBuilderServices;

    @ConditionalOnMissingBean(name = "somethingWebflowConfigurer")
    @Bean
    public CasWebflowConfigurer somethingWebflowConfigurer() {
        final SomethingWebflowConfigurer w = new SomethingWebflowConfigurer(flowBuilderServices, loginFlowDefinitionRegistry);
        return w;
    }

    @ConditionalOnMissingBean(name = "myValidateWebflowConfigurer")
    @Bean
    public CasWebflowConfigurer somethingWebflowConfigurer2() {
        final MyValidateWebflowConfigurer w = new MyValidateWebflowConfigurer(flowBuilderServices, loginFlowDefinitionRegistry);
        return w;
    }
    
    
    
    @RefreshScope
    @Bean
    public Action myValidateAction() {
        return new MyValidateAction();
    }
}